/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bookstore.action;
import com.opensymphony.xwork2.*;
import bookstore.iservice.*;
import bookstore.service.*;
import bookstore.dao.*;
import bookstore.model.*;
import static com.opensymphony.xwork2.Action.ERROR;
import static com.opensymphony.xwork2.Action.LOGIN;
import static com.opensymphony.xwork2.Action.SUCCESS;
import static java.lang.System.out;
import java.util.Map;
/**
 *
 * @author cjx
 */
public class CustomerPswAction extends ActionSupport
{
    private ICustomerService bsCustomerService =new CustomerService();
    private String oldpassword;
    private String newpassword;
    private String password;

    public String getOldpassword() {
        return oldpassword;
    }

    public void setOldpassword(String oldpassword) {
        this.oldpassword = oldpassword;
    }

    public String getNewpassword() {
        return newpassword;
    }

    public void setNewpassword(String newpassword) {
        this.newpassword = newpassword;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
   public String execute()
   {
       ActionContext ctx = ActionContext.getContext();
       Map session = ctx.getSession();
       Customer cus = (Customer)session.get("bsCustomer");
       bsCustomerService.setCustomerDao(new CustomerDao());
       Customer bsCustomer=bsCustomerService.findCustomerByNameAndPassword(cus.getName(),cus.getPassword());
       if(oldpassword.equals(bsCustomer.getPassword()) && newpassword.equals(password))
       {
       cus.setPassword(password);
       session.put("bsCustomer", cus);
       session.put("ispassword",1);
       bsCustomerService.editPassword(cus);
       }
       return SUCCESS;  
   }
    
}
